Main Questions
List inside the main question block the main questions that we seek to answer with the case study analysis:
Our main question:
- Question 1
- Question 2 etc. (You may have more than 2)
All case studies should include a disclaimer about the project, licensing info, and proper citation. See below for examples:
Disclaimer: The purpose of the Open Case Studies project is to demonstrate the use of various data science methods, tools, and software in the context of messy, real-world data. A given case study does not cover all aspects of the research process, is not claiming to be the most appropriate way to analyze a given data set, and should not be used in the context of making policy decisions without external consultation from scientific experts.
This work is licensed under the Creative Commons Attribution-NonCommercial 3.0 (CC BY-NC 3.0) United States License.
To cite this case study please use:
Wright, Carrie and Ontiveros, Michael and Jager, Leah and Taub, Margaret and Hicks, Stephanie. (2020). https://github.com/opencasestudies/ocs-bp-co2-emissions. Exploring CO2 emissions across time (Version v1.0.0).
In this space you should provide an open access link to the case study source files. This is necessary for users to get access to case study data, at a minimum. See the following example from the CO2 Emissions case study:
To access the GitHub repository for this case study see here: https://github.com//opencasestudies/ocs-bp-co2-emissions. This case study is part of a series of public health case studies for the Bloomberg American Health Initiative.
Begin the case study by describing what will be analyzed and why.
You may use headers and sub-headers like such:
Content content
Attach quotes:
Content for quotes
Attach images:
for large images from the web… might do this instead:
… and provide a link to the image source:
Use the following syntax scheme for stylizing text:
To underline something:
Bold
Italics
underline and bold
underline and bold and italics
Create a List:
1) make sure there are two spaces
2) after each item to create new line
Provide references for your images/content:
Yanosky, J. D. et al. Spatio-temporal modeling of particulate air pollution in the conterminous United States using geographic and meteorological predictors. Environ Health 13, 63 (2014).
List inside the main question block the main questions that we seek to answer with the case study analysis:
Our main question:
In this section, discuss the data science and statistical skills, methods, and concepts that will be covered by this case study. An example from the CO2 emissions case study is provided here:
In this case study, we will explore CO2 emission data from around the world. We will also focus on the US specifically to evaluate patterns of temperatures and natural disaster activity.
This case study will particularly focus on how to use different datasets that span different ranges of time, as well as how to create visualizations of patterns over time. We will especially focus on using packages and functions from the tidyverse, such as dplyr, tidyr, and ggplot2.
The tidyverse is a library of packages created by RStudio. While some students may be familiar with previous R programming packages, these packages make data science in R especially legible and intuitive.
The skills, methods, and concepts that students will be familiar with by the end of this case study are:
Data Science Learning Objectives:
dplyr for data wranglingdplyrggplot2ggplot2 plotsggplot2 plotsStatistical Learning Objectives:
After discussing the learning objectives, load all the packages used in the case study analysis in the code chunk below:
We will begin by loading the packages that we will need:
library(here)
library(readr)
library(dplyr)Provide a link to the source and briefly explain its use for each package in the following table:
| Package | Use |
|---|---|
| here | to easily load and save data |
| readr | to import the CSV file data |
The first time we use a function, we will use the :: to indicate which package we are using. Unless we have overlapping function names, this is not necessary, but we will include it here to be informative about where the functions we will use come from.
Provide some more details and background on the case study topic and its relation to public health/the world.
Describe any limitations that exist in this analysis whether it be due to the data itself, methods used, nature of the topic, etc.
There are some important considerations regarding this data analysis to keep in mind:
Limitation 1
Limitaiton 2
Describe the data to be analyzed and where it came from in this section.
If you want to make a table about variable info, use the following table template:
| Variable | Details |
|---|---|
| variable1 | Variable info – more details – more detials Example: Content content |
| variable2 | Variable info – more details – more detials Example: Content content |
Describe how to import your case study data files into R or Python:
Within your case study project folder, put the data files as they came from the source into a ‘data/raw/’ subfolder and use the here package. See the following example:
pm <-readr::read_csv(here("data", "raw", "pm25_data.csv"))At the end of the data import section, save the imported data as .rda files to allow users to stop and pick up where they left off:
save(pm, file = here::here("data", "imported", "pm25_data_imported.rda"))At the beginning of the section, include the following message:
If you have been following along but stopped, we could load our imported data like so:
load(here::here("data", "imported", "pm25_data_imported.rda"))Also provide guidance for users who may have skipped the previous section, see the following example:
An RDA version (stands for R data) of the data can be found here or slightly more directly here. Download this file and then place it in your current working directory within a subdirectory called “imported” within a directory called “data” to use the following code. We used an RStudio project and the here package to navigate to the file more easily.
load(here::here("data", "imported", "co2_data_imported.rda"))Use this section to walk through any exploration of the data conducted pre-analysis. Then, explain step-by-step the data wrangling process used to prepare the data for analysis. Note that not all case studies include a data exploration. Data exploration and wrangling may also be split into two sections.
We will also use the %>% pipe which can be used to define the input for later sequential steps. This will make more sense when we have multiple sequential steps using the same data object. To use the pipe notation we need to install and load dplyr as well.
Can include DT tables too:
library(DT)
DT::datatable(iris)(note that you can`t use these inside a click expand details section.)
Scrollable content:
# Scroll through the output!
pm %>%
distinct(state) %>%
print(n = 1e3)# A tibble: 49 x 1
state
<chr>
1 Alabama
2 Arizona
3 Arkansas
4 California
5 Colorado
6 Connecticut
7 Delaware
8 District Of Columbia
9 Florida
10 Georgia
11 Idaho
12 Illinois
13 Indiana
14 Iowa
15 Kansas
16 Kentucky
17 Louisiana
18 Maine
19 Maryland
20 Massachusetts
21 Michigan
22 Minnesota
23 Mississippi
24 Missouri
25 Montana
26 Nebraska
27 Nevada
28 New Hampshire
29 New Jersey
30 New Mexico
31 New York
32 North Carolina
33 North Dakota
34 Ohio
35 Oklahoma
36 Oregon
37 Pennsylvania
38 Rhode Island
39 South Carolina
40 South Dakota
41 Tennessee
42 Texas
43 Utah
44 Vermont
45 Virginia
46 Washington
47 West Virginia
48 Wisconsin
49 Wyoming
To make click expand section use:
text text
Note!!! You cannot use scroll features inside detail sections unless it is the last header section! Otherwise it will cause the other headers to be missing and other issues.
You can still do this if you leave an open details section like this and then have a section header at the same level as this section:
text text
Scrollable content:
# Scroll through the output!
pm %>%
distinct(state) %>%
print(n = 1e3)# A tibble: 49 x 1
state
<chr>
1 Alabama
2 Arizona
3 Arkansas
4 California
5 Colorado
6 Connecticut
7 Delaware
8 District Of Columbia
9 Florida
10 Georgia
11 Idaho
12 Illinois
13 Indiana
14 Iowa
15 Kansas
16 Kentucky
17 Louisiana
18 Maine
19 Maryland
20 Massachusetts
21 Michigan
22 Minnesota
23 Mississippi
24 Missouri
25 Montana
26 Nebraska
27 Nevada
28 New Hampshire
29 New Jersey
30 New Mexico
31 New York
32 North Carolina
33 North Dakota
34 Ohio
35 Oklahoma
36 Oregon
37 Pennsylvania
38 Rhode Island
39 South Carolina
40 South Dakota
41 Tennessee
42 Texas
43 Utah
44 Vermont
45 Virginia
46 Washington
47 West Virginia
48 Wisconsin
49 Wyoming
At the end of this section, include the following:
To allow users to skip import and wrangling we will save the data as an RDA file as well as a CSV file as this is often useful to send our data to collaborators. We will save this in a “wrangled” subdirectory of our “data” directory of our working directory.
save(pm, file = here::here("data", "wrangled", "wrangled_data.rda"))
readr::write_csv(pm, path = here::here("data","wrangled", "wrangled_data.csv"))Replace pm with the name of the data object created at the end of data wrangling.
At the beginning of the section, include the following message:
If you have been following along but stopped, we could load our wrangled data like so:
load(here::here("data", "wrangled", "wrangled_data.rda"))Also provide guidance for users who may have skipped the previous section, see the following example:
An RDA file (stands for R data) of the data can be found here or slightly more directly here. Download this file and then place it in your current working directory within a subdirectory called “wrangled” within a subdirectory called “data” to use the following code. We used an RStudio project and the here package to navigate to the file more easily.
load(here::here("data", "wrangled", "wrangled_data.rda"))Use this section to walk through step by step how the wrangled data was visualized. Explain how these visualizations improve understanding and help extract insights.
If any further wrangling was conducted in this section, please save the most recent version of the data similar to previous sections.
At the beginning of the section, include the following message:
If you have been following along but stopped, we could load our wrangled data like so:
load(here::here("data", "wrangled", "wrangled_data.rda"))Also provide guidance for users who may have skipped the previous section, see the following example:
An RDA file (stands for R data) of the data can be found here or slightly more directly here. Download this file and then place it in your current working directory within a subdirectory called “wrangled” within a subdirectory called “data” to use the following code. We used an RStudio project and the here package to navigate to the file more easily.
load(here::here("data", "wrangled", "wrangled_data.rda"))Use this section to walk through the methods and code used in the data analysis step-by-step. Explain how this analysis helps answer the main questions posed earlier in the case study.
Briefly recap everything that was covered in the case study from the motivation to data analysis. Highlight the conclusions made and suggest any limitations or future work to be done.
Construct a plot here that summarizes the conclusions found in the data, if applicable.
Suggest extra exercises using this data for students to practice the skills used in the case study.
Examples from CO2 case study:
Ask students to create a plot with labels showing the countries with the lowest CO2 emission levels.
Ask students to plot CO2 emissions and other variables (e.g. energy use) on a scatter plot, calculate the Pearson’s correlation coefficient, and discuss results.
Use this section to provide any additional information or resources on the topics and methods covered in the case study.
review of tidymodels
guide for preprocessing with recipes
guide for using GGally to create correlation plots guide for using parsnip to try different algorithms or engines recipe functions
Terms and concepts covered:
Tidyverse
RStudio cheatsheets
Inference
Regression
Different types of regression
Ordinary least squares method
Residual
Packages used in this case study:
| Package | Use |
|---|---|
| here | to easily load and save data |
| readr | to import the CSV file data |
| dplyr | to arrange/filter/select/compare specific subsets of the data |
| skimr | to get an overview of data |
| summarytools | to get an overview of data in a different style |
| pdftools | to read a PDF into R |
| magrittr | to use the %<>% pipping operator |
| purrr | to perform functions on all columns of a tibble |
| tibble | to create data objects that we can manipulate with dplyr/stringr/tidyr/purrr |
| tidyr | to separate data within a column into multiple columns |
| ggplot2 | to make visualizations with multiple layers |
devtools::session_info()- Session info ---------------------------------------------------------------
setting value
version R version 4.1.2 (2021-11-01)
os Windows 10 x64 (build 19044)
system x86_64, mingw32
ui RTerm
language (EN)
collate English_United States.1252
ctype English_United States.1252
tz America/Los_Angeles
date 2022-03-07
pandoc 2.11.4 @ C:/Program Files/RStudio/bin/pandoc/ (via rmarkdown)
- Packages -------------------------------------------------------------------
package * version date (UTC) lib source
assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.1.0)
bit 4.0.4 2020-08-04 [1] CRAN (R 4.1.0)
bit64 4.0.5 2020-08-30 [1] CRAN (R 4.1.0)
brio 1.1.3 2021-11-30 [1] CRAN (R 4.1.2)
bslib 0.3.1 2021-10-06 [1] CRAN (R 4.1.2)
cachem 1.0.6 2021-08-19 [1] CRAN (R 4.1.1)
callr 3.7.0 2021-04-20 [1] CRAN (R 4.1.0)
cli 3.2.0 2022-02-14 [1] CRAN (R 4.1.2)
crayon 1.5.0 2022-02-14 [1] CRAN (R 4.1.2)
crosstalk 1.2.0 2021-11-04 [1] CRAN (R 4.1.2)
DBI 1.1.2 2021-12-20 [1] CRAN (R 4.1.2)
desc 1.4.0 2021-09-28 [1] CRAN (R 4.1.2)
devtools 2.4.3 2021-11-30 [1] CRAN (R 4.1.2)
digest 0.6.29 2021-12-01 [1] CRAN (R 4.1.2)
dplyr * 1.0.7 2021-06-18 [1] CRAN (R 4.1.0)
DT * 0.20 2021-11-15 [1] CRAN (R 4.1.2)
ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.0)
evaluate 0.15 2022-02-18 [1] CRAN (R 4.1.2)
fansi 1.0.2 2022-01-14 [1] CRAN (R 4.1.2)
fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.0)
fs 1.5.2 2021-12-08 [1] CRAN (R 4.1.2)
generics 0.1.1 2021-10-25 [1] CRAN (R 4.1.2)
glue 1.6.1 2022-01-22 [1] CRAN (R 4.1.2)
here * 1.0.1 2020-12-13 [1] CRAN (R 4.1.1)
highr 0.9 2021-04-16 [1] CRAN (R 4.1.0)
hms 1.1.1 2021-09-26 [1] CRAN (R 4.1.2)
htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.1)
htmlwidgets 1.5.4 2021-09-08 [1] CRAN (R 4.1.1)
jquerylib 0.1.4 2021-04-26 [1] CRAN (R 4.1.1)
jsonlite 1.8.0 2022-02-22 [1] CRAN (R 4.1.2)
knitr * 1.37 2021-12-16 [1] CRAN (R 4.1.2)
lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.2)
magrittr 2.0.2 2022-01-26 [1] CRAN (R 4.1.2)
memoise 2.0.1 2021-11-26 [1] CRAN (R 4.1.2)
pillar 1.7.0 2022-02-01 [1] CRAN (R 4.1.2)
pkgbuild 1.3.1 2021-12-20 [1] CRAN (R 4.1.2)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.0)
pkgload 1.2.4 2021-11-30 [1] CRAN (R 4.1.2)
prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.1.0)
processx 3.5.2 2021-04-30 [1] CRAN (R 4.1.0)
ps 1.6.0 2021-02-28 [1] CRAN (R 4.1.0)
purrr 0.3.4 2020-04-17 [1] CRAN (R 4.1.0)
R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.1)
readr * 2.1.1 2021-11-30 [1] CRAN (R 4.1.2)
remotes 2.4.2 2021-11-30 [1] CRAN (R 4.1.2)
rlang 1.0.1 2022-02-03 [1] CRAN (R 4.1.2)
rmarkdown 2.11 2021-09-14 [1] CRAN (R 4.1.2)
rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.1.0)
rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.0)
sass 0.4.0 2021-05-12 [1] CRAN (R 4.1.1)
sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.1.2)
stringi 1.7.6 2021-11-29 [1] CRAN (R 4.1.2)
stringr 1.4.0 2019-02-10 [1] CRAN (R 4.1.0)
testthat 3.1.2 2022-01-20 [1] CRAN (R 4.1.2)
tibble 3.1.6 2021-11-07 [1] CRAN (R 4.1.2)
tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.1.0)
tzdb 0.2.0 2021-10-27 [1] CRAN (R 4.1.2)
usethis 2.1.5 2021-12-09 [1] CRAN (R 4.1.2)
utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.0)
vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.0)
vroom 1.5.7 2021-11-30 [1] CRAN (R 4.1.2)
withr 2.4.3 2021-11-30 [1] CRAN (R 4.1.2)
xfun 0.29 2021-12-14 [1] CRAN (R 4.1.2)
yaml 2.3.5 2022-02-21 [1] CRAN (R 4.1.2)
[1] C:/Users/Michael/Documents/R/win-library/4.1
[2] C:/Program Files/R/R-4.1.2/library
------------------------------------------------------------------------------